package com.fedoom.frontend.views;

import com.fedoom.frontend.controllers.EngineController;
import com.fedoom.frontend.models.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.*;

@SuppressWarnings("serial")
public class InfoView extends JFrame{
	
	//Constants
	private static final String DL_LOGO_PATH = "./logo1.bmp"; 
	
	//Data members
	private JLabel graphicLabel;
	private JButton launchButton,singleButton, modeButton, avButton, helpButton, closeButton;
	
	
	@SuppressWarnings("unused")
	private StringBuilderModel sbm;
	
	//constructor - takes model
	public InfoView(StringBuilderModel sbm){
		
		addLogo();

		this.launchButton = new JButton("Launch");
		this.singleButton = new JButton("Single player...");
		this.modeButton = new JButton("Game Mode");
		this.avButton = new JButton("Audio/Video");
		this.helpButton = new JButton("Help...");
		this.closeButton = new JButton("Quit");
		this.sbm = sbm;
		this.setTitle("Doom Legacy Launcher");

		this.launchButton.setName("launch");
		this.singleButton.setName(EngineController.single);
		this.modeButton.setName(EngineController.mode);
		this.avButton.setName(EngineController.av);
		this.helpButton.setName(EngineController.help);
		this.closeButton.setName("close");
		
		
		//layout
		JPanel panel = new JPanel();
		JPanel buttonPanel = new JPanel();
//		panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
		panel.setLayout(new BorderLayout());
		buttonPanel.setLayout(new GridLayout(4,1));
		buttonPanel.add(this.singleButton);
		buttonPanel.add(this.modeButton);
		buttonPanel.add(this.avButton);
		buttonPanel.add(this.helpButton);
//		panel.add(infoLabel);
		panel.add(launchButton,BorderLayout.NORTH);
		panel.add(this.graphicLabel, BorderLayout.CENTER);
		panel.add(buttonPanel, BorderLayout.EAST);
		panel.add(closeButton,BorderLayout.SOUTH);
		this.launchButton.setDefaultCapable(true);
		this.setContentPane(panel);
		this.pack();
		this.setSize(500,200);
		
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.pack();
	}

	/**
	 *  Displays the Doom Legacy logo in the initial screen (InfoView?).
	 *  The logo is displayed in a JLabel.
	 *  Logo is a bitmap: logo1.bmp.  
	 */
	private void addLogo() {
		File file = new File(DL_LOGO_PATH);
		BufferedImage image = null;
		
		try {
			image = ImageIO.read(file);
			this.graphicLabel = new JLabel(new ImageIcon(image));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			this.graphicLabel = new JLabel("Logo");
		}
		
	}
	
	
	//add listeners
	public void addCloseListener(ActionListener closeListener){
		
		//don't actuall perform any actions on the GUI elements from here.
		//This just links back to the controller which then links to the model
		//The model has the actual logic which the element has asked to perform
		
		closeButton.addActionListener(closeListener);
	}
	public void addLaunchListener(ActionListener launchListener){
		
		//don't actuall perform any actions on the GUI elements from here.
		//This just links back to the controller which then links to the model
		//The model has the actual logic which the element has asked to perform
		
		launchButton.addActionListener(launchListener);
	}
	public void addSingleListener(ActionListener singleListener){
		
		//don't actuall perform any actions on the GUI elements from here.
		//This just links back to the controller which then links to the model
		//The model has the actual logic which the element has asked to perform
		
		singleButton.addActionListener(singleListener);
	}
	public void addModeListener(ActionListener modeListener){
		
		//don't actuall perform any actions on the GUI elements from here.
		//This just links back to the controller which then links to the model
		//The model has the actual logic which the element has asked to perform
		
		modeButton.addActionListener(modeListener);
	}
	public void addAVListener(ActionListener avListener){
		
		//don't actuall perform any actions on the GUI elements from here.
		//This just links back to the controller which then links to the model
		//The model has the actual logic which the element has asked to perform
		
		avButton.addActionListener(avListener);
	}

	public void addHelpListener(ActionListener helpListener){
		
		//don't actuall perform any actions on the GUI elements from here.
		//This just links back to the controller which then links to the model
		//The model has the actual logic which the element has asked to perform
		
		helpButton.addActionListener(helpListener);
	}
	
	
}
